package net.maxupeng.asm74.util;

public class LogisimUtil {
    public static String convertRomToLogisimFormat(int[] rom) {
        StringBuilder sb = new StringBuilder();
        sb.append("v2.0 raw\n");
        int count = 0;
        int wrap = 0;
        for (int i = 0; i < rom.length; i++) {
            if (rom[i] != 0) {
                if (count > 0) {
                    sb.append(count).append("*0 ");
                    count = 0;
                    if (++wrap == 16) {
                        wrap = 0;
                        sb.append("\n");
                    }
                }
                sb.append(Integer.toHexString(rom[i])).append(" ");
                if (++wrap == 16) {
                    wrap = 0;
                    sb.append("\n");
                }
            } else {
                count++;
            }
        }
        if (count > 0) {
            sb.append(count).append("*0 ");
        }
        return sb.toString();
    }
}
